//自定义按钮组件

import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';

class MyButton extends StatelessWidget {
  final text;
  final pressed; //点击事件的回调，一旦设置后就不可变
  final double width;
  final double height;

  const MyButton(
      {this.text = "",
      this.width = 80.0,
      this.height = 40.0,
      this.pressed = null});

  @override
  Widget build(BuildContext context) {
    return Container(
        height: this.height,
        width: this.width,
        child: Container(
            height: 60,
            margin: EdgeInsets.all(10),
            child: ElevatedButton(
              onPressed: pressed,
              child: Text(text),
              style: ButtonStyle(
                  backgroundColor:
                      MaterialStateProperty.all(Colors.black), //背景色
                  foregroundColor: MaterialStateProperty.all(Colors.red) //字体色
                  ),
            )));
  }
}
